/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ControlEscolar.DAOs;


import com.ControlEscolar.Beans.Major;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Listico
 */
public class MajorDAO extends AbstractDAO <Major> {

    public void add(Major object) throws DAOException {
                String sql = "INSERT INTO major(ID_Major,majorName)values(\""
                        + object.getID_Major()+"\",\""
                        + object.getMajorName()+"\");";
        try {
            connection.executeUpdate(sql);
        } catch (Exception ex) {
            throw new DAOException();
        }
    }


    public int delete(String ID_Career) throws DAOException {
      String sql = "DELETE FROM major WHERE ID_Career= "+ID_Career;
        try {
            connection.executeUpdate(sql);
        } catch (Exception ex) {
            throw new DAOException();
        }
    return 0;
    }

    @Override
    public int update(Major major) throws DAOException {
        String sql="UPDATE curriculum SET majorName= \""+major.getMajorName()+"\""+
                "where ID_Major = \""+major.getID_Major()+"\"";
        try {
            connection.executeUpdate(sql);
        } catch (Exception ex) {
            throw new DAOException();
        }
        return 0;
    }

    @Override
    public ArrayList<Major> query () throws DAOException {
         try {
            String sql = "SELECT * FROM major";
            return connection.executeQuery(sql, Major.class);

        } catch (Exception ex) {
            ex.printStackTrace();
            throw new DAOException();

        }

    }

     public Major queryByID (String ID_Major) throws DAOException{
         try {
            String sql = "SELECT * FROM major where ID_Major = \""+ID_Major+"\"";
             ArrayList<Major> majorQuery=connection.executeQuery(sql, Major.class);
            return getSpecificQuery(majorQuery);
        } catch (Exception ex) {
            throw new DAOException();

        }

    }

}
